//
//  CategoryModel.m
//  DA_V
//
//  Created by 中亿世联前台 on 15/5/13.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "CategoryModel.h"
#import "AFNetworking.h"
#import "InterFace.h"
#import "EncryptionData.h"
#import "CategoryModel.h"

@implementation CategoryModel
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    

    
}

#pragma -mark 向服务器请求类型图标
- (void)getCategoryList:(NSMutableArray *)array{
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
    
    [manager POST:GetCategoryface parameters:NULL success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        
        NSString *str = responseObject[@"sign"];
        
        
        EncryptionData *data = [[EncryptionData alloc]init];
        NSString *datastr = [data decryption:str :PasswordKey];
        
        NSData* dataFromString = [datastr dataUsingEncoding:NSUTF8StringEncoding];
        
        NSDictionary *dataDic = [NSJSONSerialization  JSONObjectWithData:dataFromString options:NSJSONReadingMutableContainers error:nil];
        
        //返回成功
        if ( [[dataDic objectForKey:@"status"] isEqualToString:@"success"]) {
            
            NSLog(@"返回结果 ＝＝＝＝ %@",dataDic);
            NSArray *myDatArr =dataDic[@"data"];
//
            for (int i = 0; i <[myDatArr count]; i++) {
//
                NSDictionary *productDic = myDatArr[i];
                CategoryModel *model = [[CategoryModel alloc] init];
//
                [model setValuesForKeysWithDictionary:productDic];
//
                [array addObject:model];
            }
            [self.categoryModelDelegate getCategoryListEnd];
        }   else if ( [[dataDic objectForKey:@"status"] isEqualToString:@"failed"]) {
            [self.categoryModelDelegate getrequesterror:[dataDic objectForKey:@"status"]];

        } else{
             [self.categoryModelDelegate getrequesterror:@""];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self.categoryModelDelegate requesterror];
        NSLog(@"========== %@", [error description]);
        
    }];
    
}
@end
